from flask import jsonify, make_response, request, g
from flask_restful import Resource
from apps.settingApi.switchCase.casePrimaryKey import caseGetPrimaryKeyData
from apps.settingApi.switchCase.serializeParameter import getArgsData

from apps.settingApi.switchCase.settingCurd import getList, postList, getPk, deletePk, putPk
from apps.settingApi.api.switchDatabaseExample.model import switchDatabase1Model, switchDatabase2Model
from comm.decorator import login_required
from comm.sqlalchemyConfig import db
from comm.switchDatabase import create_session

switchDatabase1ViewModel = switchDatabase1Model
switchDatabase2ViewModel = switchDatabase2Model
# 字典操作=========================================================
class switchDatabaseListView(Resource):
    # 查询用户列表
    # @login_required()
    def get(self):
        # 多数据库的使用，如果db_name为None则使用的是默认数据库连接
        session = create_session(db_name = 'erp2')
        a_data = session.query(switchDatabase1ViewModel).all()
        objData = []
        for itm in a_data:
            objData.append({
                "id":itm.id,
                "username":itm.username
            })

        return make_response(jsonify({'msg': '成功','result': objData}), 200)